package cn.imvc.app.models;

import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import cn.imvc.app.entities.Activity;
import cn.imvc.app.repositories.ActivityRepository;
import cn.imvc.data.domain.ViewRequest;
@Service
public class ActivityModelImpl implements ActivityModel{

	@Autowired
	ActivityRepository  activityRepository;
	@Autowired
	RefRelationModel refRelationModel;
	
	public Page<Activity> find(ViewRequest viewRequest) {
		return activityRepository.findAll(viewRequest);
	}

	public Activity get(int id) {

		return activityRepository.getOne(id);
	}
	
	public Activity save(Activity activity) {
	
		return activityRepository.saveAndFlush(activity);
	}

	public Activity update(int id,Activity activity) {
		Activity loadActivity = activityRepository.getOne(id);
		BeanUtils.copyProperties(activity, loadActivity,new String[]{"id"});
		return activityRepository.saveAndFlush(loadActivity);
	}

	public void delete(int id) {
		activityRepository.delete(id);
	}
}
